// Kony

#pragma once

#include "CoreMinimal.h"
#include "MVVMViewModelBase.h"
#include "MVVM_LoadScreen.generated.h"

//选择槽位广播，这里主要是通知主场景的开始和删除按钮更变状态
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLoadSlotSelected);

class UMVVM_LoadSlot;
/**
 * 这个是MVVM 版本的加载场景类 ，这个相当于MVC类型的 控制器类 ， 这个模型是加载场景的模型类 用于包含多个存档插槽和处理界面的各种按钮操作
 */
UCLASS()
class GASC_HUANLING_API UMVVM_LoadScreen : public UMVVMViewModelBase
{
	GENERATED_BODY()
public:
	//初始化函数
	void InitializeLoadSlots();
	//广播此槽位被选中
	UPROPERTY(BlueprintAssignable)
	FLoadSlotSelected LoadSlotSelected;
	
	//加载槽试图模型类 用于蓝图设置对应的加载槽
	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<UMVVM_LoadSlot> LoadSlotViewModelClass;

	
	//通过索引获取对应槽位
	UFUNCTION(BlueprintPure)
	UMVVM_LoadSlot* GetLoadSlotViewModelByIndex(const int32 Index) const;
	//用于读写 加载槽数量
	void SetNumLoadSlots(int32 InNumLoadSlots);
	int32 GetNumLoadSlots() const {return NumLoadSlots;};

	
	//添加新游戏按钮函数 0
	UFUNCTION(BlueprintCallable)
	void NewGameButtonPressed(int32 Slot);
	//添加新槽位按钮函数 需要携带角色昵称 1
	UFUNCTION(BlueprintCallable)
	void NewSlotButtonPressed(int32 Slot, const FString& EnteredName);
	//添加选择角色槽位按钮函数 2
	UFUNCTION(BlueprintCallable)
	void SelectSlotButtonPressed(int32 Slot);
	//删除按钮点击事件
	UFUNCTION(BlueprintCallable)
	void DeleteButtonPressed();
	//选择槽位索引 开始游戏
	UFUNCTION(BlueprintCallable)
	void PlayButtonPressed();
	//加载存档数据
	void LoadData();
	
private:
	/*加载插槽指针数组，数组用于关联读取并避免被垃圾回收*/
	UPROPERTY()
	TMap<int32,UMVVM_LoadSlot*> LoadSlots;
	UPROPERTY()
	TObjectPtr<UMVVM_LoadSlot> LoadSlot_0;
	UPROPERTY()
	TObjectPtr<UMVVM_LoadSlot> LoadSlot_1;
	UPROPERTY()
	TObjectPtr<UMVVM_LoadSlot> LoadSlot_2;
	/* 加载槽部分 */
	//加载槽数量
	UPROPERTY(EditAnywhere, BlueprintReadWrite, FieldNotify, Setter, Getter, meta = (AllowPrivateAccess="true"))
	int32 NumLoadSlots;
	//当前选中的加载槽
	UPROPERTY()
	UMVVM_LoadSlot* SelectedSlot;
};
